/**
 * 
 */
package com.poc.hibernate.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.criterion.Restrictions;

import com.poc.hibernate.dao.UserDAO;
import com.poc.hibernate.factory.HibernateFactory;
import com.poc.hibernate.model.User;

/**
 * @author Charles
 *
 */
public class UserDAOHibernateImpl extends UserDAO {

	@Override
	public boolean createUser(User user) {
		try {
            startOperation();
            this.getSession().save(user);
            this.getTx().commit();
        } catch (HibernateException e) {
            return false;
        } finally {
            HibernateFactory.close(this.getSession());
        }
		return true;
	}

	@Override
	public User retrieveUser(String username) {
		User user = null;
		try {
            startOperation();
            user = (User) this.getSession().createCriteria( User.class ).
                    add( Restrictions.eq("username", username) ).
                    uniqueResult();
        } catch (HibernateException e) {
            return null;
        } finally {
            HibernateFactory.close(this.getSession());
        }
        return user;
	}

	@Override
	public List<User> retrieveAllUsers() {
		return null;
	}

	@Override
	public boolean updateUser(User user) {
		return false;
	}

	@Override
	public boolean deleteUser(User user) {
		return false;
	}

}
